/*
* Daniel Gallardo Grassot
* dgallardo@iua.upf.edu
* Universitat Pompeu Fabra
* Music Technology Group
*/

/*
	Copyright (c) 2008 Daniel Gallardo <dgallardo@iua.upf.es>
	main.cpp part of libDistortion

	Permission is hereby granted, free of charge, to any person obtaining
	a copy of this software and associated documentation files
	(the "Software"), to deal in the Software without restriction,
	including without limitation the rights to use, copy, modify, merge,
	publish, distribute, sublicense, and/or sell copies of the Software,
	and to permit persons to whom the Software is furnished to do so,
	subject to the following conditions:

	The above copyright notice and this permission notice shall be
	included in all copies or substantial portions of the Software.

	Any person wishing to distribute modifications to the Software is
	requested to send the modifications to the original developer so that
	they can be incorporated into the canonical version.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
	MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
	IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
	ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
	CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
	WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif

#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif
#include "SDL/SDL_mixer.h"

#include "Message.hxx"
#include "SDL_window.hxx"
#include "TuioClient.h"
#include "TuioDemo.h"

#define FS 44100
#define CHANNELS 2
#define SAMPLE_SIZE 2048
#define BPP 24
#define SCR_W 1024
#define SCR_H 768
#define B_TITLE "TSI-FRAMEWORK"
#define W_TITLE "TSI-FRAMEWORK"
#define FPS 60
#define FULL_SCR false

#define TUIO_PORT 3333


int main ( int argc, char** argv )
{
    Message::Info(std::string("starts"));

    TuioClient *tuioclient = new TuioClient(TUIO_PORT);

    TuioDemo* demo = new TuioDemo(tuioclient);
    tuioclient->addTuioListener(demo);
    tuioclient->start();

	
	// Obrir so SDL mixer
	if(SDL_Init(SDL_INIT_AUDIO)==-1) {
		printf("SDL_Init: %s\n", SDL_GetError());
		exit(1);
	}
	
	if(Mix_OpenAudio(FS, MIX_DEFAULT_FORMAT, CHANNELS, SAMPLE_SIZE)==-1) {
		printf("Mix_OpenAudio: %s\n", Mix_GetError());
		exit(2);
	}
	
	// Obrir finestra SDL
    SDL_window window(BPP, SCR_W, SCR_H, B_TITLE, W_TITLE, FPS, FULL_SCR);

    window.AddGraphic(demo);

    window.Run();

    tuioclient->stop();

	// Tancar SDL mixer i SDL
	Mix_CloseAudio();
	SDL_Quit();
	
    delete(demo);
    return 0;
}